#!/bin/bash
# tmux
#args_ip=$(ip -o route get to 8.8.8.8 | sed -n 's/.*src \([0-9.]\+\).*/\1/p')

#args_pwd='wowmanage.cn'
#args_name='AzerothCore'
timedatectl set-timezone Asia/Shanghai


# 开放3306端口
sudo ufw allow 3306
sudo ufw allow 8085
sudo ufw allow 3724
sudo ufw allow 7878
sudo ufw reload

sudo apt update && sudo apt install unzip zip

cd /
#git clone https://gitee.com/53957105/azerothcore-wotlk-github.git --branch cn azerothcore
git clone https://gitee.com/53957105/azerothcore-wotlk.git azerothcore
#git clone https://gitee.com/53957105/AzerothCore-wotlk-with-NPCBots.git --branch cn azerothcore
#cd /azerothcore/modules
#sh getMod.sh


cp /azerothcore/conf/dist/config.sh /azerothcore/conf/
/azerothcore/acore.sh install-deps
/azerothcore/acore.sh compiler all

#cp /azerothcore/apps/db_assembler/conf.dist.sh /azerothcore/apps/db_assembler/config.sh
#cd /azerothcore/apps/db_assembler
#./db_assembler.sh import-bases

mysql -uroot <<EOF
DROP USER IF EXISTS 'root'@'%';
CREATE USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'wowmanage.cn';
GRANT ALL PRIVILEGES ON * . * TO 'root'@'%';
FLUSH PRIVILEGES;
EOF
cp /azerothcore/apps/db_assembler/conf.dist.sh /azerothcore/apps/db_assembler/config.sh
bash /azerothcore/apps/db_assembler/db_assembler.sh import-all


# 设置允许远程登录
echo '[mysqld]' >>  /etc/mysql/my.cnf
echo 'bind-address            = 0.0.0.0' >>  /etc/mysql/my.cnf
service mysql restart

# 下载data
/azerothcore/acore.sh client-data

# 设置默认值文件
#sed -i '/^LogsDir/c LogsDir = "logs"' /azerothcore/env/dist/etc/authserver.conf.dist
#sed -i '/^TempDir/c TempDir = "temp"' /azerothcore/env/dist/etc/authserver.conf.dist
#
#sed -i '/^LogsDir/c LogsDir = "logs"' /azerothcore/env/dist/etc/worldserver.conf.dist
#sed -i '/^TempDir/c TempDir = "temp"' /azerothcore/env/dist/etc/worldserver.conf.dist
sed -i '/^SOAP.Enabled/c SOAP.Enabled = 1' /azerothcore/env/dist/etc/worldserver.conf.dist
sed -i '/^SOAP.IP/c SOAP.IP = "0.0.0.0"' /azerothcore/env/dist/etc/worldserver.conf.dist

#sed -i '/^RealmZone/c RealmZone = 16' /azerothcore/env/dist/etc/worldserver.conf.dist
#sed -i '/^DBC.Locale/c DBC.Locale = 4' /azerothcore/env/dist/etc/worldserver.conf.dist

apt install zip
cd /azerothcore
zip -r -q -o ac.zip apps/ conf/ data/ deps/ env/ modules/
